package titt.io.util.wrap;

import titt.io.IOFactory;
import titt.io.socket.in.NuderStream;
import titt.io.socket.out.TITTOutputStream;
import titt.util.io.pipe.PipeListener;
import titt.util.io.pipe.StreamPiper;

public class NuderStreamWrapper implements Wrapper {

	private StreamPiper piper = IOFactory.createStreamPiper();

	@Override
	public boolean supports(Object o) {
		return o instanceof NuderStream;
	}

	@Override
	public void writeTo(PipeListener listener, TITTOutputStream out, Object o) throws Exception {
		
		NuderStream s = (NuderStream)o;

		piper.pipe(s.getInputStream(), out.asStream(), s.getLength(), listener);
		
	}
	
	@Override
	public String getMimeType(Object o) {
		return "application/octet-stream";
	}

	@Override
	public int getLength(Object o) {
		return ((NuderStream)o).getLength();
	}


	
}
